package com.babymall.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.babymall.dao.IUsersDao;
import com.babymall.model.Users;

@Service
public class UsersService implements IUsersService {
	
	@Resource
	private IUsersDao usersDao;

	@Override
	public Users login(Users users) {
		return usersDao.login(users);
	}

	@Override
	public int register(Users users) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int editPwd(String oldPwd, String newPwd,Users user) {
		int n = 0;
		//1、先判断原密码是否正确
		if(oldPwd.equals(user.getUser_password())) {
			//修改密码并返回受影响行数
			n = usersDao.editPwd(newPwd,user.getUser_id());
		}
		return n;
	}

	@Override
	public int edit(Users users) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Map<String,Object> findAll() {
		List<Users> list = usersDao.findAll();
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", list.size());
		map.put("data", list);
		return map;
	}

}
